<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Team>" %>
<%@ Import Namespace="TeamCommunitySolution.Domain.DataLayer.Base"%>

<script type="text/javascript">
    $(function() {
        $("#DateFounded").datepicker();
        $("#DateFounded").datepicker('option', { dateFormat: "yy/mm/dd" });
    });
</script>

<script type="text/javascript">
    $.ui.dialog.defaults.bgiframe = true;

    $(document).ready(function() {
        $("#MemberSearch").dialog({
            bgiframe: true,
            autoOpen: false,
            height: 500,
            width: 400,
            zIndex: 400,
            modal: true,
            buttons: {
                'Invite': function() {
                    $.post('<%= Url.Action("InviteTeamMember", "Team") %>',
                    { formattedMemberName: $('#ToUser').val(),
                        message: $('#InviteMessage').val(),
                        teamId: $('#TeamId').val()
                    });
                    //responseCallback);
                    $(this).dialog('close');
                    return false;
                },
                Cancel: function() {
                    $(this).dialog('close');
                }
            }
        });

        $("#memberSearchInitiate").click(function() {
            $("#MemberSearch").dialog('open');
            return false;
        });

        $("input#ToUser").autocomplete('<%= Url.Action("SearchName", "SystemUser") %>');

    });
</script>

<%= Html.Hidden("Id") %>
<div style="float: left; width: 45%;">
    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="Name">
                Name:</label>
            <%= Html.TextBox("Name") %>
            <%= Html.ValidationMessage("Name", "*") %>
        </p>
        <p>
            <label for="Description">
                Description:</label>
            <%= Html.TextArea("Description") %>
            <%= Html.ValidationMessage("Description", "*") %>
        </p>
        <p>
            <label for="DateFounded">
                DateFounded:</label>
            <%= Html.TextBox("DateFounded") %>
            <%= Html.ValidationMessage("DateFounded", "*") %>
        </p>
    </fieldset>
</div>
<div style="float: right; width: 45%;">
<% if (Model != null)
   { %>
    <button id="memberSearchInitiate" class="ui-state-default ui-corner-all">
        Invite Members</button><br />
    <% } %>
    <br />
    <div id="searchForm">
        <% if (Model != null)
           {
               Html.RenderPartial("~/Views/Team/MemberSearch.ascx", Model);
           } %>
    </div>
    <table width="100%">
        <tr>
            <th>
            </th>
            <th>
                First Name
            </th>
            <th>
                Last Name
            </th>
            <th>
                Call Sign
            </th>
        </tr>
        <% if (Model != null)
           {
               foreach (var item in Model.MemberList)
               { %>
        <tr>
            <td>
                <%= Html.ActionLink("Edit", "Edit", "Team", new { team = item.Id }, null)%>
                |
                <%= Html.ActionLink("Members", "MembersList", "Team", new { team = item.Id })%>
            </td>
            <td>
                <%= Html.Encode(item.FirstName)%>
            </td>
            <td>
                <%= Html.Encode(item.LastName)%>
            </td>
            <td>
                <%= Html.Encode(item.NickName)%>
            </td>
        </tr>
        <% }
           } %>
    </table>
</div>
<div style="clear: both; width: 100%">
    <p>
        <% if (Model == null)
           {%>
        <input type="submit" value="Create" />
        <%}
           else
           { %>
        <input type="submit" value="Update" />
        <%} %>
    </p>
</div>
